package boot3.mapper;

import boot3.pojo.Livechat;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface LivechatMapper {
    //根据聊天室的编号，获取聊天室现有的用户的ID
    @Select("select user_id from livechat where chatroom_id=#{chatroom_id}")
    public List<String> getLiveroomUsers(String chatroom_id);
    //向数据库中添加实时聊天室的成员
    @Insert("insert into livechat (chatroom_id,user_id,start_time) value(#{chatroom_id},#{user_id},#{start_time})")
    public boolean setLiveroomUsers(String chatroom_id,String user_id,String start_time);
    //从数据库中将已经离开聊天室的人删除
    @Delete("delete from livechat where user_id=#{user_id} and chatroom_id=#{chatroom_id}")
    public boolean deleteLiveroomUsers(String user_id,String chatroom_id);
    //聊天室解散，根据聊天室ID删除所有在其中的用户
    @Delete("delete from livechat where chatroom_id=#{chatroom_id}")
    public Boolean deleteAllUsers(String chatroom_id);
    //根据聊天室的ID获取该聊天室中所有用户
    @Select("select * from livechat where chatroom_id=#{chatroom_id}")
    public List<Livechat>getAllUsers(String chatroom_id);
}
